<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
// var rotate = function(nums, k) {
//     let arr1 = nums.slice(0, nums.length - k)
//     console.log('arr1:', arr1)
//     let arr2 = nums.splice(nums.length - k, k)
//     console.log('arr2:', arr2)
//     console.log('nums:', nums)
//     return arr2.concat(arr1)
// };
var rotate = function(nums, k) {
    let x = k % nums.length
    let arr = [...nums]
    nums.splice(0, 0)
    for (let i = arr.length - x; i < arr.length; i++) {
        nums.push(arr[i])
    }
    for (let i = 0; i < arr.length - x; i++) {
        nums.push(arr[i])
    }
    return nums
};
let arr = [1,2,3,4,5,6,7]

console.log(arr)
console.log(3)
console.log(rotate(arr, 3))


console.log([-1,-100,3,99])
console.log(2)
console.log(rotate([-1,-100,3,99], 2))

</script>
</body>
</html>